//
//  XUPhotoCollectionView.m
//  新浪微博
//
//  Created by xuwenxin on 15-4-16.
//  Copyright (c) 2015年 xuwenxin. All rights reserved.
//

#import "XUPhotoCollectionView.h"
#import "HMPhoto.h"

@interface XUPhotoCollectionView ()

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *laout;

@end

@implementation XUPhotoCollectionView

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

    // 每个cell的大小
    self.laout.itemSize = [UIScreen mainScreen].bounds.size;
    // 分页显示
    self.collectionView.pagingEnabled = YES;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark <UICollectionViewDataSource>

//- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
//#warning Incomplete method implementation -- Return the number of sections
//    return 1;
//}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete method implementation -- Return the number of items in the section
    // 4
    return self.photos.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

# warning 图片浏览器需要完善
    [self photoBroswer:cell indexPath:indexPath];
    
    return cell;
}

- (void)photoBroswer:(UICollectionViewCell *)cell indexPath:(NSIndexPath *)indexPath
{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:cell.bounds];
    scrollView.backgroundColor = [UIColor redColor];
    scrollView.minimumZoomScale = 0.5;
    scrollView.maximumZoomScale = 1.5;
    
    UIImageView *img = [[UIImageView alloc] init];
    HMPhoto *model =[HMPhoto objectWithKeyValues:self.photos[indexPath.item]];
    NSString *str = model.thumbnail_pic;
    [str stringByReplacingOccurrencesOfString:@"thumbnail" withString:@"bmiddle"];
    NSURL *url = [NSURL URLWithString:str];
    [img sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"icon.jpg"]];
    
    [img sizeToFit];
    [scrollView addSubview:img];
    [cell.contentView addSubview:scrollView];
    
    
}
@end
